<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
include("../navigation.php");
// $contents=new Contents();
// $_GET["dir"]==0 && (isset($_GET["pres"]) && Contents::presence_rights($_GET["pres"]))

if (!empty($_GET["name"])) {
	$GLOBALS["linkzusatz"]="";
	$act_doc=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."content_documents WHERE id2='". $_GET["name"] ."' and deleted='0'");
	if (mysql_num_rows($act_doc)==1) {
		$row_doc=mysql_fetch_object($act_doc);
		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."content_dirs WHERE id='". $row_doc->ofdir ."'");
		if (mysql_num_rows($act_dir)==1) {
			$row_act=mysql_fetch_object($act_dir);
			if (!Contents::presence_rights($row_act->presence)) {
				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
			}
			$GLOBALS["linkzusatz"].="&name=". $row_doc->id2;
		} else {
			die("Da ist irgendwas schief gelaufen.");
		}
	} else {
		die("Da ist irgendwas schief gelaufen.");
	}
}

if (!empty($_GET["editrepetition"]) && !empty($_GET["editimage"])) {
	$queryfield=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."content_images WHERE repetition='". $_GET["editrepetition"] ."' and name='". $_GET["editimage"] ."' and deleted='0'");
	if (mysql_num_rows($queryfield)<1) {
		mysql_query("INSERT INTO ". $GLOBALS["db_pref"] ."content_images SET repetition='". $_GET["editrepetition"] ."', name='". $_GET["editimage"] ."', image='', created_by='". $_SESSION["userid"] ."', created_date='". idate("U") ."'");
	}
	$GLOBALS["linkzusatz"].="&editrepetition=". $_GET["editrepetition"];
	$GLOBALS["linkzusatz"].="&editimage=". $_GET["editimage"];
	if(!empty($_POST["filename"])) {
		mysql_query("UPDATE ". $GLOBALS["db_pref"] ."content_images SET image='". $_POST["filename"] ."' WHERE repetition='". $_GET["editrepetition"] ."' and name='". $_GET["editimage"] ."'");
		?>
		<script language="JavaScript" type="text/javascript">
		<!--
		window.opener.location.reload();
		// -->
		</script>
		<?php
	}
	if (!empty($_POST["url"]) && !empty($_POST["type"])) {
		mysql_query("INSERT INTO ". $GLOBALS["db_pref"] ."content_links SET type='". $_POST["type"] ."', url='". $_POST["url"] ."', target='". $_POST["target"] ."'");
		mysql_query("UPDATE ". $GLOBALS["db_pref"] ."content_images SET link='". mysql_insert_id() ."' WHERE repetition='". $_GET["editrepetition"] ."' and name='". $_GET["editimage"] ."'");
		?>
		<script language="JavaScript" type="text/javascript">
		<!--
		window.opener.location.reload();
		// -->
		</script>
		<?php
	} elseif (!empty($_POST["nolink"]) && $_POST["nolink"]==1) {
		mysql_query("UPDATE ". $GLOBALS["db_pref"] ."content_images SET link='0' WHERE repetition='". $_GET["editrepetition"] ."' and name='". $_GET["editimage"] ."'");
		?>
		<script language="JavaScript" type="text/javascript">
		<!--
		window.opener.location.reload();
		// -->
		</script>
		<?php
	}
} else {
	die("Es wurde eine falsche URL aufgerufen!");
}
$graphic=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."content_images WHERE repetition='". $_GET["editrepetition"] ."' and name='". $_GET["editimage"] ."' and deleted='0'");
if (mysql_num_rows($graphic)==1) {
	$row_graphic=mysql_fetch_object($graphic);
}

echo "<"."?xml version=\"1.0\"?".">";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title><?php echo getsetting("sitename"); ?> - Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    function submitForm(type, url) {
    	document.forms[1].elements["url"].value=url;
    	document.forms[1].elements["type"].value=type;
    	document.forms[1].submit();
    }
    function submitImageForm(filename) {
    	document.forms[0].elements["filename"].value=filename;
    	document.forms[0].submit();
    }
    // -->
    </script>
  </head>

  <body id="edit">
    <div id="media">
    	<p id="pageheadline">W&auml;hlen Sie eine Grafik:</p>
      	<form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
      	<input type="hidden" name="filename" value=""/>
    	<?php
    	list_media($row_act->presence, 1);
    	echo "<br />";
   		?>
   		</form>
    </div>
    <div id="link" style="visibility:visible">
      <form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
      <input type="hidden" name="url" value=""/>
      <input type="hidden" name="type" value=""/>
      <p id="pageheadline">W&auml;hlen Sie einen Zielframe:</p>
      <select size="1" name="target">
    	  <option value="">Kein spezieller Frame</option>
    	  <option value="_blank">Neues Fenster</option>
    	  <option value="_self">Selber Frame</option>
    	  <option value="_parent">&uuml;bergeordneter Frame</option>
      </select>
      <p id="pageheadline">Kein Link:</p>
          <input type="checkbox" name="nolink" value="1" onclick="document.forms[1].submit();" />
      <p id="pageheadline">Externer Link:</p>
    	  <input type="text" value="http://" name="extlink" size="40" />
    	  <input type="button" value="Einf&uuml;gen" onclick="submitForm('2', document.forms[1].elements['extlink'].value);"/>
  	  <p id="pageheadline">W&auml;hlen Sie eine Seite:</p>
   	  <?php
   	  list_contents($row_act->presence);
   	  echo "<br />";
   	  ?>
  	  <p id="pageheadline">W&auml;hlen Sie einen Navigationspunkt:</p>
   	  <?php
   	  list_navigations($row_act->presence);
   	  echo "<br />";
   	  ?>
  	  <p id="pageheadline">W&auml;hlen Sie eine Datei:</p>
   	  <?php
   	  list_media($row_act->presence, 0, 1);
   	  echo "<br />";
   	  ?>
   	  </form>
    </div>
  </body>
</html>